import java.util.Scanner;

public class Main {

    public static int n;
    public static int m;
    public static int[] arr;
    public static int[] color;
    public static long sum;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        m = sc.nextInt();
        arr = new int[n];
        color = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            color[i] = sc.nextInt();
        }

        int[] temp = new int[3];
        boolean[] flag = new boolean[n];
        dfs(temp, 0, flag);

        System.out.println(sum % 10007);

        sc.close();
    }

    /**
     *
     * @param temp 三元组 (x, y, z)
     * @param index 三元组元素下标
     */
    public static void dfs(int[] temp, int index, boolean[] flag) {
        if (index == 3) {
            int x = temp[0];
            int y = temp[1];
            int z = temp[2];
            if (y - x == z - y && x < y && y < z && color[x] == color[z]) {
                sum += (long)(x + z + 2) * (arr[x] + arr[z]) % 10007;
            }
            return;
        }

        for (int i = 0; i < n; i++) {
            if (!flag[i]) {
                temp[index] = i;
                flag[i] = true;
                dfs(temp, index + 1, flag);

                //回溯
                temp[index] = 0;
                flag[i] = false;
            }
        }
    }
}
